package com.huawei.rbac.web.Interceptor;

import com.huawei.rbac.domain.Employee;
import com.huawei.rbac.util.UserContext;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class CheckLoginInterceptor extends HandlerInterceptorAdapter{


    public boolean preHandle(HttpServletRequest request,
                             HttpServletResponse response, Object handler)
            throws Exception {
        //1:获取登录凭证
        Employee emp = UserContext.getCurrentUser();
        if(emp == null){
            //没有登录
            response.sendRedirect("/login.jsp");
            return false;
        }
        return true; ///放行
    }
}
